@model ZKEACMS.Shop.Models.Order
@{
    Script.Reqiured("validate").AtFoot();
    Script.Reqiured("tinymce").AtFoot();
}

<div class="panel panel-default">
    <div class="panel-heading">
        @L("修改")
    </div>
    <div class="panel-body">
        @using (Html.BeginForm())
        {
            @Html.EditorForModel()
            <div class="toolBar">                
                @if (Authorizer.Authorize(ZKEACMS.Shop.PermissionKeys.ManageOrder))
                {
                    <input type="submit" class="btn btn-primary" value="@L("保存")" data-value="@ActionType.Update" />
                }
                @if (Authorizer.Authorize(ZKEACMS.Shop.PermissionKeys.ViewOrderPayment) && Model.PaymentID.IsNotNullAndWhiteSpace())
                {
                    <a href="javascript:void(0)" class="btn btn-primary payment-info">@L("支付信息")</a>
                }
                @if (Authorizer.Authorize(ZKEACMS.Shop.PermissionKeys.RefundOrder) && Model.PaymentID.IsNotNullAndWhiteSpace() && Model.RefundID.IsNullOrEmpty())
                {
                    <a href="javascript:void(0)" class="btn btn-primary refund">@L("退款")</a>
                }
                @if (Authorizer.Authorize(ZKEACMS.Shop.PermissionKeys.ViewOrderRefund) && Model.RefundID.IsNotNullAndWhiteSpace())
                {
                    <a href="javascript:void(0)" class="btn btn-primary refund-info">@L("退款信息")</a>
                }
                @*@if (Authorizer.Authorize(ZKEACMS.Shop.PermissionKeys.CloseOrder) && Model.OrderStatus == (int)ZKEACMS.Shop.OrderStatus.UnPaid)
                {
                    <a href="javascript:void(0)" class="btn btn-danger close-order">关闭订单</a>
                }*@
                <input type="button" class="btn btn-default cancel" value="@L("取消")" />                
            </div>
        }
    </div>
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">@L("信息")</h4>
            </div>
            <div class="modal-body">
                ...
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">@L("关闭")</button>
            </div>
        </div>
    </div>
</div>

@using (Script.AtFoot())
{
    <script type="text/javascript">
        $("#OrderStatus").prop("disabled", true);
        $(document).on("click", ".payment-info", function () {
            Easy.Block();
            $.post("@Url.Action("PaymentInfo", new { id=Model.ID })", function (html) {
                Easy.UnBlock();
                $("#myModalLabel").text("@L("支付信息")")
                $(".modal-body").html(html);
                $(".modal").modal();
            }, "html");
        });
        $(document).on("click", ".refund", function () {
            if (!$("#Refund").val()) {
                Easy.ShowMessageBox("@L("提示")", "@L("请输入退款金额")");
                $("#Refund").focus();
                return;
            }
            if (!$("#RefundReason").val()) {
                Easy.ShowMessageBox("@L("提示")", "@L("请输入退款原因")");
                $("#RefundReason").focus();
                return;
            }
            if ($("form").validate().element("#Refund")) {
                if (Number($("#Refund").val()) > Number($("#Total").val())) {
                    return;
                }
                Easy.ShowMessageBox("@L("提示")", "@L("确定要退款吗？")", function () {
                    Easy.Block();
                    $.post("@Url.Action("Refund", new { id = Model.ID })", { amount: $("#Refund").val(), reason: $("#RefundReason").val() }, function (data) {
                        if (data.hasViolation) {
                            Easy.ShowMessageBox("@L("提示")", data.errorMessage);
                        } else {
                            Easy.ShowMessageBox("@L("提示")", "@L("退款成功！")", function () { window.location.reload(true); },false);
                        }
                    });
                 }, true);
            }
        });
        $(document).on("click", ".refund-info", function () {
            Easy.Block();
            $.post("@Url.Action("RefundInfo", new { id=Model.ID })", function (html) {
                Easy.UnBlock();
                $("#myModalLabel").text("@L("退款信息")")
                $(".modal-body").html(html);
                $(".modal").modal();
            }, "html");
        });
        $(document).on("click", ".close-order", function () {
            Easy.Block();
            $.post("@Url.Action("CloseOrder", new { id=Model.ID })", function (data) {
                if (data.hasViolation) {
                    Easy.ShowMessageBox("@L("提示")", data.errorMessage);
                } else {
                    Easy.ShowMessageBox("@L("提示")", "@L("订单已关闭！")", function () { window.location.reload(true); }, false);
                }
            });
        });
        $("form").submit(function () { 
            $("#OrderStatus").prop("disabled", false);
        });
    </script>

}